<template>
  <a-modal
    :title="title"
    :width="500"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="验证码">
          <a-input placeholder="请输入验证码" v-decorator="['code', validatorRules.code]" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import { codeEdit, codeGet } from '@/api/blog/blogList';
import { Slime } from '@/mixins/slime';
export default {
  name: 'buildModal',
  mixins: [Slime],
  data() {
    return {
      title: '操作',
      model: {},
      form: this.$form.createForm(this),
      validatorRules: {
        code: { rules: [{ required: true, message: '请输入验证码!' }] },
      },
    }
  },
  created() {},
  methods: {
    add() {
      this.edit({})
    },
    edit() {
      this.visible = true
      let that = this
      codeGet()
        .then((res) => {
          console.log(res.result)
          if (res.code == 0) {
            that.$nextTick(() => {
              that.form.setFieldsValue({
                code: res.result
              })
            })
          } else {
            that.$message.warning(res.message)
          }
        })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    //点击确定
    handleOk() {
      const that = this;
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let formData = {...values}
          //订购须知
          console.log(formData)
          codeEdit(formData)
          .then((res) => {
            if (res.success) {
              that.$message.success('提交成功')
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          })
          .finally(() => {
            that.confirmLoading = false
            that.close()
          })
        }
      })
    },
    //关闭
    handleCancel() {
      this.close()
    },
  }, 
}
</script>

<style lang="less" scoped>
</style>